<!DOCTYPE html>
<html xmlns:th="http://www.springframework.org/schema/data/jaxb">
<head>
    <meta charset="UTF-8">
    <title th:text="${companyName}">title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" th:href="@{imgs/favicon.ico}" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{lib/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{css/okadmin.css}"/>
    <link rel="stylesheet" th:href="@{font/iconfont.css}">
    <link rel="stylesheet" th:href="@{lib/animate/animate.css}"/>
    <link rel="stylesheet" th:href="@{lib/nprogress/nprogress.css}">
</head>
<body class="login-body">
<div class="login-box animated rotateIn">
    <div class="head"></div>
    <div class="input-box">
        <form class="layui-form">
            <input type="text" name="username" id="username" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
            <input type="password" name="password" id="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
            <input type="submit" value="登 录" lay-submit lay-filter="login">
        </form>
    </div>
    <div class="copyright">
        © 2018-<span id="endYear"></span> <span th:text="${companyName}"></span>. All rights reserved.<br/><br/>
        <a href="http://www.beian.miit.gov.cn" th:text="${icpNumber}"></a>
    </div>
</div>
<script th:src="@{lib/layui/layui.js}"></script>
<script th:src="@{lib/nprogress/nprogress.js}"></script>
<script th:src="@{js/encrypt.js}"></script>
<script type="text/javascript">
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    }

    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;

        // 修改copyright结束时间
        var data = new Date();
        var year = data.getFullYear();
        $("#endYear").text(year);

        // 登陆逻辑
        form.on('submit(login)', function (data) {
            layer.msg("登陆中...", {icon: 6, time: 1000, anim: 4}, function () {
                loginAction();
            });
            return false;
        });
    });

    function loginAction(){
        var $ = layui.jquery;

        $.ajax({
            url : "login",
            method : "post",
            dataType : "json",
            data : {
                username : $("#username").val(),
                password : hex_md5($("#password").val())
            },
            async: false,
            success : function(result){
                if(result.success){
                    location.href = "index";
                }else{
                    layer.msg(result.msg);
                }
            },
            error: function () {
                layer.msg("服务器异常, 稍后重试!");
            }
        });
    }
</script>
</body>
</html>
